package com.hp.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class IOUtil {
	public static String getStringByIn(InputStream in, String encode) {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		int temp = -1;
		try {
			temp = in.read();

			while (temp != -1) {
				output.write(temp);
				temp = in.read();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			return new String(output.toByteArray(), encode);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		}
	}

	public static InputStream getInSreamByFile(String filename) {
		InputStream stream = null;
		stream = PropUtil.class.getResourceAsStream("/config/" + filename);
		return stream;
	}
}
